#include "Help.h"


void Help::UTF8ToGB2312(std::string& utf8,std::string& gb2312)
{
	int length=MultiByteToWideChar(CP_UTF8,0,utf8.c_str(),-1,NULL,0);
	wchar_t *pwText=new wchar_t[length];
	MultiByteToWideChar(CP_UTF8,0,utf8.c_str(),-1,pwText,length);

	length=WideCharToMultiByte(936,NULL,pwText,-1,NULL,0,NULL,FALSE);
	char*psText=new char[length];
	WideCharToMultiByte(936,NULL,pwText,-1,psText,length,NULL,FALSE);

	std::string re(psText);
	gb2312=re;

	delete []pwText;
	delete []psText;
}

void Help::GB2312ToUTF8(std::string& gb2312,std::string& utf8)
{
	int length=MultiByteToWideChar(936,0,gb2312.c_str(),-1,NULL,0);
	wchar_t *pwText=new wchar_t[length];
	MultiByteToWideChar(936,0,gb2312.c_str(),-1,pwText,length);

	length=WideCharToMultiByte(CP_UTF8,NULL,pwText,-1,NULL,0,NULL,FALSE);
	char*psText=new char[length];
	WideCharToMultiByte(CP_UTF8,NULL,pwText,-1,psText,length,NULL,FALSE);

	std::string re(psText);
	utf8=re;

	delete []pwText;
	delete []psText;
}
